home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GEMFUNCS / FRMEFLAG.C < prev    next >
C/C++ Source or Header  |  1993-03-20  |  8KB  |  233 lines

  1. /*****************************************************************************
  2.  *
  3.  ****************************************************************************/
  4.  
  5. #include "gemfintl.h"
  6. #include <osbind.h>
  7.  
  8. static char GFAR cant_flagit_alert[] = "[3]"
  9.     "[An error has occured with an"
  10.     "|item you selected or modified."
  11.     "|There are not enough system"
  12.     "|resources to flag the object"
  13.     "|and display the error message."
  14.     "][ Continue ]"
  15.     ;
  16.  
  17. static OBJECT GFAR msgtree[] = {
  18.     -1,  1,  1, G_BOX,    NONE,    SHADOWED, (_Ob_spec_t)0x00FF2100L, 0, 0, 0, 0,
  19.      0,  2, 21, G_BOX,    NONE,    NORMAL,   (_Ob_spec_t)0x00000000L, 1, 0, 0, 0,
  20.      3, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 0, 0, 1,
  21.      4, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 1, 0, 1,
  22.      5, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 2, 0, 1,
  23.      6, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 3, 0, 1,
  24.      7, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 4, 0, 1,
  25.      8, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 5, 0, 1,
  26.      9, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 6, 0, 1,
  27.     10, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 7, 0, 1,
  28.     11, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 8, 0, 1,
  29.     12, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0, 9, 0, 1,
  30.     13, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0,10, 0, 1,
  31.     14, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0,11, 0, 1,
  32.     15, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0,12, 0, 1,
  33.     16, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0,13, 0, 1,
  34.     17, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0,14, 0, 1,
  35.     18, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0,15, 0, 1,
  36.     19, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0,16, 0, 1,
  37.     20, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0,17, 0, 1,
  38.     21, -1, -1, G_TEXT, NONE,    NORMAL,   (_Ob_spec_t)0L,           0,18, 0, 1,
  39.      1, -1, -1, G_TEXT, LASTOB, NORMAL,   (_Ob_spec_t)0L,           0,19, 0, 1,
  40. };
  41.  
  42. #define TEXT_BOX        1
  43. #define FIRST_TEXT_LINE 2
  44.  
  45. /**************************************************************************
  46.  * treeplace - Figure out a good place to hang the text box on the screen.
  47.  *************************************************************************/
  48.  
  49. #ifdef GEMFAST_PROTOS
  50.   static void treeplace(register OBJECT *ptree, register VRECT *vdirect)
  51. #else
  52.   static void treeplace(ptree, vdirect)
  53.     register OBJECT *ptree;
  54.     register VRECT    *vdirect;
  55. #endif
  56. {
  57.     register short      wrkint1, wrkint2, wrkint3;
  58.  
  59.     wrkint1 = vdirect->v_y1;
  60.     wrkint2 = gl_vwout[1] - vdirect->v_y2;
  61.     wrkint3 = ptree->ob_height + gl_hchar + 1;
  62.  
  63.     if (wrkint1 > wrkint2) {
  64.         ptree->ob_y = wrkint1 - wrkint3;        /* place above object */
  65.     } else {
  66.         ptree->ob_y = vdirect->v_y2 + gl_hchar; /* place below object */
  67.     }
  68.  
  69.     wrkint1 = vdirect->v_x1;
  70.     wrkint2 = gl_vwout[0] - vdirect->v_x2;
  71.     wrkint3 = ptree->ob_width + gl_wchar + 1;
  72.  
  73.     if (wrkint1 > wrkint2) {
  74.         ptree->ob_x = wrkint1 - wrkint3;
  75.     } else {
  76.         ptree->ob_x = vdirect->v_x2 + gl_wchar;
  77.     }
  78.  
  79.     frm_confine(ptree, &gl_rwdesk);
  80. }
  81.  
  82. /**************************************************************************
  83.  *
  84.  * frm_eflag - Flag an erronious object.
  85.  *
  86.  *************************************************************************/
  87.  
  88. #ifdef GEMFAST_PROTOS
  89.   short frm_eflag(OBJECT *ptree, short obj, char *fmt, ...)
  90. #else
  91.   short frm_eflag(ptree, obj, fmt)
  92.     OBJECT *ptree;
  93.     short obj;
  94.     char *fmt;
  95. #endif
  96. {
  97.     va_list     args;
  98.     short          vdi_handle;
  99.     short          maxwidth = 0;
  100.     short          numlines;
  101.     short          msglen;
  102.     void        *blitbuffer;
  103.     char        *pmsgtext;
  104.     char        *msglines[FRM_DSMAXSTRINGS+1];
  105.     GRECT        flagrect;
  106.     GRECT        msgrect;
  107.     GRECT        saverect;
  108.     VRECT        flagbox;
  109.     XMULTI        xm;
  110.     short        status;
  111.     static short  initdone = FALSE;
  112.  
  113.     /*----------------------------------------------------------------------
  114.      * Start by ringing the user's bell <snicker>.  Believe it or not,
  115.      * doing this first helps hide the fact that it takes about 1/4 second
  116.      * to get the error display up on the screen.    (Don't ask me why, do
  117.      * I look like a psychologist or something?)
  118.      *--------------------------------------------------------------------*/
  119.  
  120.     Bconout(2,'\007');                                   /* ding...       */
  121.  
  122.     if (!initdone) {
  123.         initdone = TRUE;
  124.         rsc_treefix(msgtree);
  125.         msgtree[TEXT_BOX].ob_y = gl_hchar / 2;
  126.     }
  127.  
  128.     if (0 == (vdi_handle = apl_vshared())) {
  129.         status = gfErr_vdi_handle;
  130.         goto ERROR_EXIT;
  131.     }
  132.  
  133.     /*----------------------------------------------------------------------
  134.      * Calc the rectangles involved with the object to be flagged.
  135.      *--------------------------------------------------------------------*/
  136.  
  137.     obj_clcalc(ptree, obj, &flagrect, NULL);
  138.     rc_gadjust(&flagrect, 5, 3);
  139.     rc_gtov(&flagrect, &flagbox);
  140.  
  141.     /*----------------------------------------------------------------------
  142.      * Fix up the error message text tree.    The fixup will change the
  143.      * size of the tree. Upon return, calc the location of the tree, (note
  144.      * that this process can fail, if we can't fit the text on the screen).
  145.      * Calc rectangles involved with the final placement of the text tree.
  146.      *--------------------------------------------------------------------*/
  147.  
  148.     va_start(args, fmt);
  149.     pmsgtext = _FrmVFormat(fmt, args, &msglen);
  150.     va_end(args);
  151.  
  152.     if (msglen < 0) {
  153.         status = msglen;
  154.         goto ERROR_EXIT;
  155.     }
  156.  
  157.     _FrmNL2DS(pmsgtext, msglines, NULL, FRM_DSMAXSTRINGS);
  158.     numlines = _FrmDS2Obj(msglines, &msgtree[FIRST_TEXT_LINE], NULL,
  159.                             &maxwidth, FRM_DSMAXSTRINGS);
  160.  
  161.     _FrmTrWidths(msgtree, TEXT_BOX, gl_wchar * maxwidth);
  162.     msgtree[TEXT_BOX].ob_height = gl_hchar * numlines;
  163.  
  164.     msgtree[ROOT].ob_width    = gl_wchar * (maxwidth + 2);
  165.     msgtree[ROOT].ob_height = gl_hchar * (numlines + 1);
  166.  
  167.     treeplace(msgtree, &flagbox);
  168.  
  169.     obj_clcalc(msgtree, ROOT, &msgrect, NULL);
  170.     rc_copy(&msgrect,  &saverect);
  171.     rc_union(&flagrect, &saverect);
  172.     rc_gadjust(&saverect, 3, 2);
  173.  
  174.     /*----------------------------------------------------------------------
  175.      * Save the screen area, display the text message and flag the
  176.      * object.    Wait for a button or key, upon event restore the screen.
  177.      *--------------------------------------------------------------------*/
  178.  
  179.     wind_update(BEG_MCTRL);
  180.     wind_update(BEG_UPDATE);
  181.  
  182.     if (NULL == (blitbuffer = grf_memblit(GRF_NORMAL, NULL, &saverect))) {
  183.         status = gfErr_no_memory;
  184.         goto ERROR_EXIT;
  185.     }
  186.  
  187.     graf_mouse(M_OFF, 0L);
  188.     vsl_width(vdi_handle, 3);
  189.     vsl_color(vdi_handle, 2);                            /* red */
  190.     vs_clip(vdi_handle, TRUE, (short *)&gl_rfscrn);
  191.     v_rbox(vdi_handle, (short *)&flagbox);                       /* flag object */
  192.     vs_clip(vdi_handle, FALSE, (short *)&gl_rfscrn);
  193.     vsl_color(vdi_handle, 1);
  194.     vsl_width(vdi_handle, 1);
  195.     graf_mouse(M_ON, 0L);
  196.  
  197.     objc_draw(msgtree, R_TREE, MAX_DEPTH, RECTVALS(&msgrect)); /* show text  */
  198.  
  199.     xm.mflags    = MU_BUTTON | MU_KEYBD;
  200.     xm.mbclicks = 1;
  201.     xm.mbmask    = 1;
  202.     xm.mbstate    = 1;
  203.  
  204.     evnx_multi(&xm);
  205.  
  206.     grf_memblit(GRF_NORMAL, blitbuffer, &saverect);
  207.  
  208.     if (xm.mwhich & MU_BUTTON) {
  209.         xm.mbstate = 0;              /* wait for button-up */
  210.         xm.mflags  = MU_BUTTON;
  211.         evnx_multi(&xm);
  212.     }
  213.  
  214.     wind_update(END_UPDATE);
  215.     wind_update(END_MCTRL);
  216.  
  217.     _FrmVFree(pmsgtext);
  218.  
  219.     /*----------------------------------------------------------------------
  220.      * return success.
  221.      *--------------------------------------------------------------------*/
  222.  
  223.     return gfSuccess;
  224.  
  225. ERROR_EXIT:
  226.  
  227.     form_alert(1,cant_flagit_alert);
  228.     return status;
  229. }
  230.  
  231.  
  232.  
  233.